#include "dbconfig.h"

dbconfigForm::dbconfigForm(QWidget *parent) :
	QDialog(parent),
	ui(new Ui::dbconfigDialog)
{
	ui->setupUi(this);
}

dbconfigForm::~dbconfigForm()
{
	if (ui) {
		delete ui;
		ui = NULL;
	}
}

void dbconfigForm::showEvent(QShowEvent *event)
{
	event = event;
	loadConfig();
}

void dbconfigForm::closeEvent(QCloseEvent * event)
{
	event = event;
	saveConfig();
}

void dbconfigForm::on_btn_exit_clicked()
{
	this->close();
}

void dbconfigForm::on_btn_ok_clicked()
{
	saveConfig();
	QMessageBox::about(this, QObject::tr("success"),
		QObject::tr("save parameters success!"));
}

void dbconfigForm::loadConfig()
{
	QSettings dbconfig("dbconfig.ini", QSettings::IniFormat);
	ui->edit_dsn->setText(dbconfig.value("dsn").toString());
	ui->edit_username->setText(dbconfig.value("user").toString());
	ui->edit_pwd->setText(dbconfig.value("pwd").toString());
}

void dbconfigForm::saveConfig()
{
	QSettings dbconfig("dbconfig.ini", QSettings::IniFormat);
	dbconfig.setValue("dsn", ui->edit_dsn->text());
	dbconfig.setValue("user", ui->edit_username->text());
	dbconfig.setValue("pwd", ui->edit_pwd->text());
}
